<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>门店关注券</title>
  <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
  <meta content="yes" name="apple-mobile-web-app-capable"/>
  <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
  <meta content="telephone=no" name="format-detection"/>
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
{foreach name="coupon" item="vo"}
    {if condition="$vo.is_receive gt 0"}
    <div style="border:2px solid red;">
        <p>标题：{$vo.name}</p>
        <p>使用类型：{if condition="$vo.cat_id eq 0"}通用{else /}{$vo.title}{/if}</p>
        <p>使用条件：满￥{$vo.morethan}减￥{$vo.reduce}</p>
        <a href="javascript:;">已领取</a>
    </div>
    {else /}
    <div>
        <p>标题：{$vo.name}</p>
        <p>使用类型：{if condition="$vo.cat_id eq 0"}通用{else /}{$vo.title}{/if}</p>
        <p>使用条件：满￥{$vo.morethan}减￥{$vo.reduce}</p>
        <a href="javascript:;"  onclick="receive(this,{$vo.id})">领取</a>
    </div>
    {/if}
{/foreach}
</body>
</html>
<script>
    /**
     * 领取门店的关注券
     * @param id 关注券id
     */
    function receive(obj,id){
        if(id == ''){
            alert('没有找到领取的优惠券');
        }
        $.post("{:url('StoreIndex/receive_store_coupon')}?id="+id,
            {id:id},
            function(data){
                if(data.code == 1){
                    $(obj).removeAttr('onclick');
                    $(obj).text('已领取');
                    alert('领取成功');
                }else{
                    alert('领取失败');
                }
            }
        );
    }
</script>